package com.xuanxing123.model;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

import javax.persistence.*;
import static javax.persistence.GenerationType.IDENTITY;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;

@Entity
@Table(name="product_module",catalog="xuanxing")
@Searchable
@XmlRootElement
public class ProductModule extends BaseObject implements Serializable {
    private Long id;
    private Module module;
    private Product product;
    private Integer score;
    private Boolean enabled;

    @Id @GeneratedValue(strategy=IDENTITY) @SearchableId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }

    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="module_id", nullable=false)
    public Module getModule() {
        return this.module;
    }
    
    public void setModule(Module module) {
        this.module = module;
    }

    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="product_id", nullable=false)
    public Product getProduct() {
        return this.product;
    }
    
    public void setProduct(Product product) {
        this.product = product;
    }
    
    @Column(name="score", nullable=false)
    @SearchableProperty
    public Integer getScore() {
        return this.score;
    }
    
    public void setScore(Integer score) {
        this.score = score;
    }

    @Column(name="enabled")
    @SearchableProperty
    public Boolean getEnabled() {
        return this.enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }
    
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ProductModule pojo = (ProductModule) o;

        if (module != null ? !module.equals(pojo.module) : pojo.module != null) return false;
        if (product != null ? !product.equals(pojo.product) : pojo.product != null) return false;
        if (score != null ? !score.equals(pojo.score) : pojo.score != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (module != null ? module.hashCode() : 0);
        result = 31 * result + (product != null ? product.hashCode() : 0);
        result = 31 * result + (score != null ? score.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("module").append("='").append(getModule()).append("', ");
        sb.append("product").append("='").append(getProduct()).append("', ");
        sb.append("score").append("='").append(getScore()).append("'");
        sb.append("enabled").append("='").append(getEnabled()).append("'");
        sb.append("]");
      
        return sb.toString();
    }

}
